<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>The Inv Construct</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'The Inv Construct' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../intern.html">Inter Modules</a></li><li><a href="index.html">bytecode</a></li><li><a href="index.html#5">Chapter 5: Code Constructs</a></li><li><b>The Inv Construct</b></li></ul></div>
<p class="purpose">Defining the inv construct.</p>

<ul class="toc"><li><a href="5-tic.html#SP1">&#167;1. Definition</a></li><li><a href="5-tic.html#SP2">&#167;2. Instructions</a></li><li><a href="5-tic.html#SP7">&#167;7. Creating from textual Inter syntax</a></li><li><a href="5-tic.html#SP8">&#167;8. Writing to textual Inter syntax</a></li><li><a href="5-tic.html#SP9">&#167;9. Access functions</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Definition.</b>For what this does and why it is used, see <a href="../inter/M-ti.html" class="internal">Textual Inter (in inter)</a>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">InvInstruction::define_construct</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::define_construct</span></span>:<br/>Inter Constructs - <a href="3-ic.html#SP15">&#167;15</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_construct</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IC</span><span class="plain-syntax"> = </span><a href="3-ic.html#SP1" class="function-link"><span class="function-syntax">InterInstruction::create_construct</span></a><span class="plain-syntax">(</span><span class="constant-syntax">INV_IST</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"inv"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-ic.html#SP8" class="function-link"><span class="function-syntax">InterInstruction::specify_syntax</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"inv TOKEN"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-ic.html#SP4" class="function-link"><span class="function-syntax">InterInstruction::data_extent_always</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="constant-syntax">2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-ic.html#SP3" class="function-link"><span class="function-syntax">InterInstruction::allow_in_depth_range</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="constant-syntax">INFINITELY_DEEP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-ic.html#SP3" class="function-link"><span class="function-syntax">InterInstruction::permit</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="constant-syntax">INSIDE_CODE_PACKAGE_ICUP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-ic.html#SP3" class="function-link"><span class="function-syntax">InterInstruction::permit</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="constant-syntax">CAN_HAVE_CHILDREN_ICUP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="constant-syntax">CONSTRUCT_READ_MTID</span><span class="plain-syntax">, </span><a href="5-tic.html#SP7" class="function-link"><span class="function-syntax">InvInstruction::read</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="constant-syntax">CONSTRUCT_TRANSPOSE_MTID</span><span class="plain-syntax">, </span><a href="5-tic.html#SP3" class="function-link"><span class="function-syntax">InvInstruction::transpose</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="constant-syntax">CONSTRUCT_VERIFY_MTID</span><span class="plain-syntax">, </span><a href="5-tic.html#SP4" class="function-link"><span class="function-syntax">InvInstruction::verify</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="constant-syntax">CONSTRUCT_WRITE_MTID</span><span class="plain-syntax">, </span><a href="5-tic.html#SP8" class="function-link"><span class="function-syntax">InvInstruction::write</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="constant-syntax">CONSTRUCT_VERIFY_CHILDREN_MTID</span><span class="plain-syntax">, </span><a href="5-tic.html#SP5" class="function-link"><span class="function-syntax">InvInstruction::verify_children</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. Instructions.</b>In bytecode, the frame of an <span class="extract"><span class="extract-syntax">inv</span></span> instruction is laid out with the
compulsory words &mdash; see <a href="2-in.html" class="internal">Inter Nodes</a> &mdash; followed by:
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">METHOD_INV_IFLD</span><span class="plain-syntax">  (</span><span class="constant-syntax">DATA_IFLD</span><span class="plain-syntax"> + </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">INVOKEE_INV_IFLD</span><span class="plain-syntax"> (</span><span class="constant-syntax">DATA_IFLD</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">)</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>It's arguably the case that <span class="extract"><span class="extract-syntax">inv</span></span> is three instructions, not one, but it is
also arguable the other way, and here we are. The <span class="extract"><span class="extract-syntax">METHOD_INV_IFLD</span></span> indicates
which variant we are looking at:
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">PRIMITIVE_INVMETH</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">FUNCTION_INVMETH</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">OPCODE_INVMETH</span><span class="plain-syntax"> </span><span class="constant-syntax">3</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">inter_error_message</span><span class="plain-syntax"> *</span><span class="function-syntax">InvInstruction::new_primitive</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::new_primitive</span></span>:<br/><a href="5-tic.html#SP7_1">&#167;7.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_bookmark</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prim_s</span><span class="plain-syntax">, </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">level</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_error_location</span><span class="plain-syntax"> *</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">GID</span><span class="plain-syntax"> = </span><a href="2-st.html#SP16" class="function-link"><span class="function-syntax">InterSymbolsTable::id_from_symbol</span></a><span class="plain-syntax">(</span><a href="2-bkm.html#SP7" class="function-link"><span class="function-syntax">InterBookmark::tree</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">), </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">prim_s</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax"> = </span><a href="2-in.html#SP5" class="function-link"><span class="function-syntax">Inode::new_with_2_data_fields</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">, </span><span class="constant-syntax">INV_IST</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="comment-syntax">/* METHOD_INV_IFLD:  */</span><span class="plain-syntax"> </span><span class="constant-syntax">PRIMITIVE_INVMETH</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="comment-syntax">/* INVOKEE_INV_IFLD: */</span><span class="plain-syntax"> </span><span class="identifier-syntax">GID</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">level</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_error_message</span><span class="plain-syntax"> *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="3-vi.html#SP1" class="function-link"><span class="function-syntax">VerifyingInter::instruction</span></a><span class="plain-syntax">(</span><a href="2-bkm.html#SP6" class="function-link"><span class="function-syntax">InterBookmark::package</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">), </span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">E</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">E</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="2-np.html#SP3" class="function-link"><span class="function-syntax">NodePlacement::move_to_moving_bookmark</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">IBM</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">inter_error_message</span><span class="plain-syntax"> *</span><span class="function-syntax">InvInstruction::new_function_call</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::new_function_call</span></span>:<br/><a href="5-tic.html#SP7_3">&#167;7.3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_bookmark</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">function_s</span><span class="plain-syntax">, </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">level</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_error_location</span><span class="plain-syntax"> *</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax"> = </span><a href="2-in.html#SP5" class="function-link"><span class="function-syntax">Inode::new_with_2_data_fields</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">, </span><span class="constant-syntax">INV_IST</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="comment-syntax">/* METHOD_INV_IFLD:  */</span><span class="plain-syntax"> </span><span class="constant-syntax">FUNCTION_INVMETH</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="comment-syntax">/* INVOKEE_INV_IFLD: */</span><span class="plain-syntax"> </span><a href="2-st.html#SP17" class="function-link"><span class="function-syntax">InterSymbolsTable::id_at_bookmark</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">, </span><span class="identifier-syntax">function_s</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">level</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_error_message</span><span class="plain-syntax"> *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="3-vi.html#SP1" class="function-link"><span class="function-syntax">VerifyingInter::instruction</span></a><span class="plain-syntax">(</span><a href="2-bkm.html#SP6" class="function-link"><span class="function-syntax">InterBookmark::package</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">), </span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">E</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">E</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="2-np.html#SP3" class="function-link"><span class="function-syntax">NodePlacement::move_to_moving_bookmark</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">IBM</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">inter_error_message</span><span class="plain-syntax"> *</span><span class="function-syntax">InvInstruction::new_assembly</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::new_assembly</span></span>:<br/><a href="5-tic.html#SP7_2">&#167;7.2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_bookmark</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">opcode_name</span><span class="plain-syntax">, </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">level</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_error_location</span><span class="plain-syntax"> *</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax"> = </span><a href="2-in.html#SP5" class="function-link"><span class="function-syntax">Inode::new_with_2_data_fields</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">, </span><span class="constant-syntax">INV_IST</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="comment-syntax">/* METHOD_INV_IFLD:  */</span><span class="plain-syntax"> </span><span class="constant-syntax">OPCODE_INVMETH</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="comment-syntax">/* INVOKEE_INV_IFLD: */</span><span class="plain-syntax"> </span><a href="2-tw.html#SP7" class="function-link"><span class="function-syntax">InterWarehouse::create_text_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">, </span><span class="identifier-syntax">opcode_name</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">level</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_error_message</span><span class="plain-syntax"> *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="3-vi.html#SP1" class="function-link"><span class="function-syntax">VerifyingInter::instruction</span></a><span class="plain-syntax">(</span><a href="2-bkm.html#SP6" class="function-link"><span class="function-syntax">InterBookmark::package</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">), </span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">E</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">E</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="2-np.html#SP3" class="function-link"><span class="function-syntax">NodePlacement::move_to_moving_bookmark</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">IBM</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">InvInstruction::transpose</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::transpose</span></span>:<br/><a href="5-tic.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_construct</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> *</span><span class="identifier-syntax">grid</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">grid_extent</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_error_message</span><span class="plain-syntax"> **</span><span class="identifier-syntax">E</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">METHOD_INV_IFLD</span><span class="plain-syntax">] == </span><span class="constant-syntax">OPCODE_INVMETH</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">INVOKEE_INV_IFLD</span><span class="plain-syntax">] = </span><span class="identifier-syntax">grid</span><span class="plain-syntax">[</span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">INVOKEE_INV_IFLD</span><span class="plain-syntax">]];</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>Verification consists only of sanity checks.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">InvInstruction::verify</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::verify</span></span>:<br/><a href="5-tic.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_construct</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owner</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_error_message</span><span class="plain-syntax"> **</span><span class="identifier-syntax">E</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">METHOD_INV_IFLD</span><span class="plain-syntax">]) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">PRIMITIVE_INVMETH:</span>
<span class="plain-syntax">            *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="3-vi.html#SP3" class="function-link"><span class="function-syntax">VerifyingInter::GSID_field</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="constant-syntax">INVOKEE_INV_IFLD</span><span class="plain-syntax">, </span><span class="constant-syntax">PRIMITIVE_IST</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (*</span><span class="identifier-syntax">E</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">OPCODE_INVMETH:</span>
<span class="plain-syntax">            *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="3-vi.html#SP7" class="function-link"><span class="function-syntax">VerifyingInter::text_field</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">owner</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="constant-syntax">INVOKEE_INV_IFLD</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (*</span><span class="identifier-syntax">E</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">FUNCTION_INVMETH:</span>
<span class="plain-syntax">            *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="3-vi.html#SP2" class="function-link"><span class="function-syntax">VerifyingInter::SID_field</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">owner</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="constant-syntax">INVOKEE_INV_IFLD</span><span class="plain-syntax">, </span><span class="constant-syntax">INVALID_IST</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (*</span><span class="identifier-syntax">E</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">default:</span>
<span class="plain-syntax">            *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="2-in.html#SP15" class="function-link"><span class="function-syntax">Inode::error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"bad invocation method"</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>Verification of the child nodes, however, is not entirely passive, as we
shall see.
</p>

<p class="commentary">This function implements a primitive typechecker for invocations, though it is
more notable for what it doesn't check than for what it does: Inter is a very
permissive language. The rules are:
</p>

<ul class="items"><li>(a) An assembly opcode can have any number of arguments, of any category.
</li><li>(b) A function call can have any number of arguments, provided they all have
category <span class="extract"><span class="extract-syntax">val</span></span>.
</li><li>(c) A primitive invocation must have exactly the number of arguments in its
signature, whose categories must be exactly as given in the signature. For
example, if the signature of the primitive invoked at <span class="extract"><span class="extract-syntax">P</span></span> is <span class="extract"><span class="extract-syntax">ref val val -&gt; void</span></span>,
then <span class="extract"><span class="extract-syntax">P</span></span> needs to have exactly three children, of categories <span class="extract"><span class="extract-syntax">ref</span></span>, <span class="extract"><span class="extract-syntax">val</span></span>, <span class="extract"><span class="extract-syntax">val</span></span>.
</li></ul>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">InvInstruction::verify_children</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::verify_children</span></span>:<br/><a href="5-tic.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_construct</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_error_message</span><span class="plain-syntax"> **</span><span class="identifier-syntax">E</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">METHOD_INV_IFLD</span><span class="plain-syntax">] == </span><span class="constant-syntax">PRIMITIVE_INVMETH</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">arity_as_invoked</span><span class="plain-syntax">=0;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_THROUGH_INTER_CHILDREN</span><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">) </span><span class="identifier-syntax">arity_as_invoked</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax"> = </span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">tree</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prim_s</span><span class="plain-syntax"> = </span><a href="5-tic.html#SP9" class="function-link"><span class="function-syntax">InvInstruction::primitive</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="5-tic.html#SP5_1" class="named-paragraph-link"><span class="named-paragraph">Opportunistically improve the use of indirect function call primitives</span><span class="named-paragraph-number">5.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="5-tic.html#SP5_2" class="named-paragraph-link"><span class="named-paragraph">Check there are exactly the right number of arguments</span><span class="named-paragraph-number">5.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_THROUGH_INTER_CHILDREN</span><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">i</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[0] == </span><span class="constant-syntax">SPLAT_IST</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[0] != </span><span class="constant-syntax">INV_IST</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[0] != </span><span class="constant-syntax">REF_IST</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[0] != </span><span class="constant-syntax">LAB_IST</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[0] != </span><span class="constant-syntax">CODE_IST</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[0] != </span><span class="constant-syntax">VAL_IST</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[0] != </span><span class="constant-syntax">EVALUATION_IST</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[0] != </span><span class="constant-syntax">REFERENCE_IST</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[0] != </span><span class="constant-syntax">CAST_IST</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[0] != </span><span class="constant-syntax">COMMENT_IST</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[0] != </span><span class="constant-syntax">ASSEMBLY_IST</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="2-in.html#SP15" class="function-link"><span class="function-syntax">Inode::error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"forbidden instruction under an inv"</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">METHOD_INV_IFLD</span><span class="plain-syntax">] != </span><span class="constant-syntax">OPCODE_INVMETH</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="5-tic.html#SP5_3" class="named-paragraph-link"><span class="named-paragraph">Check that the category of the child matches what is expected</span><span class="named-paragraph-number">5.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5_1" class="paragraph-anchor"></a><b>&#167;5.1. </b>This is the part which is not passive. If we observe an indirect function
call made by invoking a primitive such as <span class="extract"><span class="extract-syntax">!indirect0</span></span>, but with the wrong
number of arguments, then we change it to the version with the right arity.
(For example, if we see <span class="extract"><span class="extract-syntax">!indirect1</span></span> with three arguments, we correct it to
<span class="extract"><span class="extract-syntax">!indirect3</span></span>.)
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Opportunistically improve the use of indirect function call primitives</span><span class="named-paragraph-number">5.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-tpc5.html#SP8" class="function-link"><span class="function-syntax">PrimitiveInstruction::arity</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prim_s</span><span class="plain-syntax">) != </span><span class="identifier-syntax">arity_as_invoked</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">BIP</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Primitives::to_BIP</span><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">prim_s</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Primitives::is_BIP_for_indirect_call_returning_value</span><span class="plain-syntax">(</span><span class="identifier-syntax">BIP</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Primitives::arity_too_great_for_indirection</span><span class="plain-syntax">(</span><span class="identifier-syntax">arity_as_invoked</span><span class="plain-syntax">-1)) {</span>
<span class="plain-syntax">                *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="2-in.html#SP15" class="function-link"><span class="function-syntax">Inode::error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"over-complex indirect call"</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">prim_s</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Primitives::from_BIP</span><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Primitives::BIP_for_indirect_call_returning_value</span><span class="plain-syntax">(</span><span class="identifier-syntax">arity_as_invoked</span><span class="plain-syntax"> - </span><span class="constant-syntax">1</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><a href="5-tic.html#SP10" class="function-link"><span class="function-syntax">InvInstruction::write_primitive</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">prim_s</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Primitives::is_BIP_for_void_indirect_call</span><span class="plain-syntax">(</span><span class="identifier-syntax">BIP</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">prim_s</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Primitives::from_BIP</span><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Primitives::BIP_for_void_indirect_call</span><span class="plain-syntax">(</span><span class="identifier-syntax">arity_as_invoked</span><span class="plain-syntax"> - </span><span class="constant-syntax">1</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><a href="5-tic.html#SP10" class="function-link"><span class="function-syntax">InvInstruction::write_primitive</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">prim_s</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-tic.html#SP5">&#167;5</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP5_2" class="paragraph-anchor"></a><b>&#167;5.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Check there are exactly the right number of arguments</span><span class="named-paragraph-number">5.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-tpc5.html#SP8" class="function-link"><span class="function-syntax">PrimitiveInstruction::arity</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prim_s</span><span class="plain-syntax">) != </span><span class="identifier-syntax">arity_as_invoked</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">err</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::new</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"this inv of %S should have %d argument(s), but has %d"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">prim_s</span><span class="plain-syntax">)?(</span><a href="2-sym.html#SP19" class="function-link"><span class="function-syntax">InterSymbol::identifier</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prim_s</span><span class="plain-syntax">)):</span><span class="identifier-syntax">I</span><span class="string-syntax">"&lt;unknown&gt;"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><a href="4-tpc5.html#SP8" class="function-link"><span class="function-syntax">PrimitiveInstruction::arity</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prim_s</span><span class="plain-syntax">), </span><span class="identifier-syntax">arity_as_invoked</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="2-in.html#SP15" class="function-link"><span class="function-syntax">Inode::error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-tic.html#SP5">&#167;5</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP5_3" class="paragraph-anchor"></a><b>&#167;5.3. </b>In effect, this is a limited form of typechecker for invocations. For example,
if the invocation has the signature <span class="extract"><span class="extract-syntax">ref val -&gt; void</span></span>, then we expect its first
child (operand 0) to be a <span class="extract"><span class="extract-syntax">ref</span></span>, and its second (operand 1) to be a <span class="extract"><span class="extract-syntax">val</span></span>.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Check that the category of the child matches what is expected</span><span class="named-paragraph-number">5.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">cat_found</span><span class="plain-syntax"> = </span><a href="5-tic.html#SP6" class="function-link"><span class="function-syntax">InvInstruction::evaluated_category</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">cat_needed</span><span class="plain-syntax"> = </span><span class="constant-syntax">VAL_PRIM_CAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">METHOD_INV_IFLD</span><span class="plain-syntax">] == </span><span class="constant-syntax">PRIMITIVE_INVMETH</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">cat_needed</span><span class="plain-syntax"> = </span><a href="4-tpc5.html#SP8" class="function-link"><span class="function-syntax">PrimitiveInstruction::operand_category</span></a><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><a href="5-tic.html#SP9" class="function-link"><span class="function-syntax">InvInstruction::primitive</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">), </span><span class="identifier-syntax">i</span><span class="plain-syntax">-1);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">cat_found</span><span class="plain-syntax"> != </span><span class="identifier-syntax">cat_needed</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">invokee</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">METHOD_INV_IFLD</span><span class="plain-syntax">] == </span><span class="constant-syntax">PRIMITIVE_INVMETH</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">invokee</span><span class="plain-syntax"> = </span><a href="5-tic.html#SP9" class="function-link"><span class="function-syntax">InvInstruction::primitive</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">METHOD_INV_IFLD</span><span class="plain-syntax">] == </span><span class="constant-syntax">FUNCTION_INVMETH</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">invokee</span><span class="plain-syntax"> = </span><a href="5-tic.html#SP9" class="function-link"><span class="function-syntax">InvInstruction::function</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">err</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::new</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"operand %d of inv '%S' should be %s, but this is %s"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">i</span><span class="plain-syntax">, (</span><span class="identifier-syntax">invokee</span><span class="plain-syntax">)?(</span><a href="2-sym.html#SP19" class="function-link"><span class="function-syntax">InterSymbol::identifier</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">invokee</span><span class="plain-syntax">)):</span><span class="identifier-syntax">I</span><span class="string-syntax">"&lt;unknown&gt;"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><a href="4-tpc5.html#SP7" class="function-link"><span class="function-syntax">PrimitiveInstruction::cat_name</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">cat_needed</span><span class="plain-syntax">),</span>
<span class="plain-syntax">            </span><a href="4-tpc5.html#SP7" class="function-link"><span class="function-syntax">PrimitiveInstruction::cat_name</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">cat_found</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="2-in.html#SP15" class="function-link"><span class="function-syntax">Inode::error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-tic.html#SP5">&#167;5</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>So this is the category for the value produced (if any) by an instruction.
The default is 0, which means <span class="extract"><span class="extract-syntax">void</span></span>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="function-syntax">InvInstruction::evaluated_category</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::evaluated_category</span></span>:<br/><a href="5-tic.html#SP5_3">&#167;5.3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[0]) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">REF_IST:</span><span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">REF_PRIM_CAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">REFERENCE_IST:</span><span class="plain-syntax">  </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">REF_PRIM_CAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">VAL_IST:</span><span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">VAL_PRIM_CAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">EVALUATION_IST:</span><span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">VAL_PRIM_CAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">CAST_IST:</span><span class="plain-syntax">       </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">VAL_PRIM_CAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">ASSEMBLY_IST:</span><span class="plain-syntax">   </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">VAL_PRIM_CAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">LAB_IST:</span><span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">LAB_PRIM_CAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">CODE_IST:</span><span class="plain-syntax">       </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">CODE_PRIM_CAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">INV_IST:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">METHOD_INV_IFLD</span><span class="plain-syntax">] == </span><span class="constant-syntax">PRIMITIVE_INVMETH</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="4-tpc5.html#SP8" class="function-link"><span class="function-syntax">PrimitiveInstruction::result_category</span></a><span class="plain-syntax">(</span>
<span class="plain-syntax">                    </span><a href="5-tic.html#SP9" class="function-link"><span class="function-syntax">InvInstruction::primitive</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">VAL_PRIM_CAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. Creating from textual Inter syntax.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">InvInstruction::read</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::read</span></span>:<br/><a href="5-tic.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_construct</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_bookmark</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_line_parse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ilp</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_error_location</span><span class="plain-syntax"> *</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_error_message</span><span class="plain-syntax"> **</span><span class="identifier-syntax">E</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">invoked_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ilp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">mr</span><span class="plain-syntax">.</span><span class="identifier-syntax">exp</span><span class="plain-syntax">[0];</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::get_first_char</span><span class="plain-syntax">(</span><span class="identifier-syntax">invoked_text</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="character-syntax">'!'</span><span class="plain-syntax">: </span><span class="named-paragraph-container code-font"><a href="5-tic.html#SP7_1" class="named-paragraph-link"><span class="named-paragraph">This is a primitive invocation</span><span class="named-paragraph-number">7.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="character-syntax">'@'</span><span class="plain-syntax">: </span><span class="named-paragraph-container code-font"><a href="5-tic.html#SP7_2" class="named-paragraph-link"><span class="named-paragraph">This is an assembly opcode invocation</span><span class="named-paragraph-number">7.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">default:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="5-tic.html#SP7_3" class="named-paragraph-link"><span class="named-paragraph">This is a function call invocation</span><span class="named-paragraph-number">7.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7_1" class="paragraph-anchor"></a><b>&#167;7.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">This is a primitive invocation</span><span class="named-paragraph-number">7.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax"> = </span><a href="2-bkm.html#SP7" class="function-link"><span class="function-syntax">InterBookmark::tree</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prim_s</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">        </span><a href="2-st.html#SP7" class="function-link"><span class="function-syntax">InterSymbolsTable::symbol_from_name</span></a><span class="plain-syntax">(</span><a href="2-it.html#SP3" class="function-link"><span class="function-syntax">InterTree::global_scope</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">), </span><span class="identifier-syntax">invoked_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">prim_s</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">prim_s</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Primitives::declare_one_named</span><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            &amp;(</span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">site</span><span class="plain-syntax">.</span><span class="identifier-syntax">strdata</span><span class="plain-syntax">.</span><span class="identifier-syntax">package_types_bookmark</span><span class="plain-syntax">), </span><span class="identifier-syntax">invoked_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">prim_s</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="3-ie.html#SP4" class="function-link"><span class="function-syntax">InterErrors::quoted</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"'inv' on undeclared primitive"</span><span class="plain-syntax">, </span><span class="identifier-syntax">invoked_text</span><span class="plain-syntax">, </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="5-tic.html#SP3" class="function-link"><span class="function-syntax">InvInstruction::new_primitive</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">, </span><span class="identifier-syntax">prim_s</span><span class="plain-syntax">, (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">ilp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">indent_level</span><span class="plain-syntax">, </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-tic.html#SP7">&#167;7</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP7_2" class="paragraph-anchor"></a><b>&#167;7.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">This is an assembly opcode invocation</span><span class="named-paragraph-number">7.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="5-tic.html#SP3" class="function-link"><span class="function-syntax">InvInstruction::new_assembly</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">, </span><span class="identifier-syntax">invoked_text</span><span class="plain-syntax">, (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">ilp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">indent_level</span><span class="plain-syntax">, </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-tic.html#SP7">&#167;7</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP7_3" class="paragraph-anchor"></a><b>&#167;7.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">This is a function call invocation</span><span class="named-paragraph-number">7.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">function_s</span><span class="plain-syntax"> = </span><a href="3-iitf.html#SP5" class="function-link"><span class="function-syntax">TextualInter::find_symbol</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">, </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="identifier-syntax">invoked_text</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">E</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">function_s</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="3-ie.html#SP4" class="function-link"><span class="function-syntax">InterErrors::quoted</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"'inv' on unknown function"</span><span class="plain-syntax">, </span><span class="identifier-syntax">invoked_text</span><span class="plain-syntax">, </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="5-tic.html#SP3" class="function-link"><span class="function-syntax">InvInstruction::new_function_call</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">, </span><span class="identifier-syntax">function_s</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">ilp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">indent_level</span><span class="plain-syntax">, </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-tic.html#SP7">&#167;7</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. Writing to textual Inter syntax.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">InvInstruction::write</span><button class="popup" onclick="togglePopup('usagePopup10')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup10">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::write</span></span>:<br/><a href="5-tic.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_construct</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IC</span><span class="plain-syntax">, </span><span class="identifier-syntax">OUTPUT_STREAM</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><a href="5-tic.html#SP9" class="function-link"><span class="function-syntax">InvInstruction::method</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">PRIMITIVE_INVMETH:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"inv %S"</span><span class="plain-syntax">, </span><a href="2-sym.html#SP19" class="function-link"><span class="function-syntax">InterSymbol::identifier</span></a><span class="plain-syntax">(</span><a href="5-tic.html#SP9" class="function-link"><span class="function-syntax">InvInstruction::primitive</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">)));</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">OPCODE_INVMETH:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"inv %S"</span><span class="plain-syntax">, </span><a href="2-in.html#SP14" class="function-link"><span class="function-syntax">Inode::ID_to_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">INVOKEE_INV_IFLD</span><span class="plain-syntax">]));</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">FUNCTION_INVMETH:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"inv "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="3-iitf.html#SP10" class="function-link"><span class="function-syntax">TextualInter::write_symbol_from</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="constant-syntax">INVOKEE_INV_IFLD</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. Access functions.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="function-syntax">InvInstruction::method</span><button class="popup" onclick="togglePopup('usagePopup11')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup11">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::method</span></span>:<br/><a href="5-tic.html#SP8">&#167;8</a><br/>The Reference Construct - <a href="5-trc2.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-in.html#SP13" class="function-link"><span class="function-syntax">Inode::is</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="constant-syntax">INV_IST</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">METHOD_INV_IFLD</span><span class="plain-syntax">];</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="function-syntax">InvInstruction::function</span><button class="popup" onclick="togglePopup('usagePopup12')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup12">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::function</span></span>:<br/><a href="5-tic.html#SP5_3">&#167;5.3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><a href="2-in.html#SP13" class="function-link"><span class="function-syntax">Inode::is</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="constant-syntax">INV_IST</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><a href="5-tic.html#SP9" class="function-link"><span class="function-syntax">InvInstruction::method</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">) == </span><span class="constant-syntax">FUNCTION_INVMETH</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="2-st.html#SP14" class="function-link"><span class="function-syntax">InterSymbolsTable::symbol_from_ID_at_node</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="constant-syntax">INVOKEE_INV_IFLD</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="function-syntax">InvInstruction::primitive</span><button class="popup" onclick="togglePopup('usagePopup13')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup13">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::primitive</span></span>:<br/><a href="5-tic.html#SP5">&#167;5</a>, <a href="5-tic.html#SP5_3">&#167;5.3</a>, <a href="5-tic.html#SP6">&#167;6</a>, <a href="5-tic.html#SP8">&#167;8</a><br/>Transmigration - <a href="2-trn.html#SP5">&#167;5</a><br/>The Reference Construct - <a href="5-trc2.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><a href="2-in.html#SP13" class="function-link"><span class="function-syntax">Inode::is</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="constant-syntax">INV_IST</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><a href="5-tic.html#SP9" class="function-link"><span class="function-syntax">InvInstruction::method</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">) == </span><span class="constant-syntax">PRIMITIVE_INVMETH</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="2-st.html#SP14" class="function-link"><span class="function-syntax">InterSymbolsTable::global_symbol_from_ID_at_node</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="constant-syntax">INVOKEE_INV_IFLD</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="function-syntax">InvInstruction::opcode</span><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><a href="2-in.html#SP13" class="function-link"><span class="function-syntax">Inode::is</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="constant-syntax">INV_IST</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><a href="5-tic.html#SP9" class="function-link"><span class="function-syntax">InvInstruction::method</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">) == </span><span class="constant-syntax">OPCODE_INVMETH</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="2-in.html#SP14" class="function-link"><span class="function-syntax">Inode::ID_to_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">INVOKEE_INV_IFLD</span><span class="plain-syntax">]);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. </b>In <a href="2-trn.html" class="internal">Transmigration</a> and for various other reasons, it's necessary to change
an invocation into a primitive, or a different primitive. So:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">InvInstruction::write_primitive</span><button class="popup" onclick="togglePopup('usagePopup14')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup14">Usage of <span class="code-font"><span class="function-syntax">InvInstruction::write_primitive</span></span>:<br/><a href="5-tic.html#SP5_1">&#167;5.1</a><br/>Transmigration - <a href="2-trn.html#SP5_1">&#167;5.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prim</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-in.html#SP13" class="function-link"><span class="function-syntax">Inode::is</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="constant-syntax">INV_IST</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">METHOD_INV_IFLD</span><span class="plain-syntax">] = </span><span class="constant-syntax">PRIMITIVE_INVMETH</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="constant-syntax">INVOKEE_INV_IFLD</span><span class="plain-syntax">] = </span><a href="2-st.html#SP16" class="function-link"><span class="function-syntax">InterSymbolsTable::id_from_symbol</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">prim</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"wrote primitive to non-invocation"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="5-tec.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-bm.html">1</a></li><li class="progresschapter"><a href="2-it.html">2</a></li><li class="progresschapter"><a href="3-ic.html">3</a></li><li class="progresschapter"><a href="4-tcc.html">4</a></li><li class="progresscurrentchapter">5</li><li class="progresssection"><a href="5-tac.html">tac</a></li><li class="progresssection"><a href="5-tcc.html">tcc</a></li><li class="progresssection"><a href="5-tcc2.html">tcc2</a></li><li class="progresssection"><a href="5-tec.html">tec</a></li><li class="progresscurrent">tic</li><li class="progresssection"><a href="5-tlc.html">tlc</a></li><li class="progresssection"><a href="5-tlc2.html">tlc2</a></li><li class="progresssection"><a href="5-tlc3.html">tlc3</a></li><li class="progresssection"><a href="5-trc.html">trc</a></li><li class="progresssection"><a href="5-trc2.html">trc2</a></li><li class="progresssection"><a href="5-tsc.html">tsc</a></li><li class="progresssection"><a href="5-tvc.html">tvc</a></li><li class="progresschapter"><a href="6-tpc.html">6</a></li><li class="progressnext"><a href="5-tlc.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

